package top.wangjiu.reactive.rpc.autoconfigure.server;

import org.springframework.context.SmartLifecycle;

/**
 * @ClassName RpcServerStartStopLifecycle
 * @Description TODO
 * @Author wangjiu
 * @Date 2021/8/11 6:16 下午
 */
public class RpcServerStartStopLifecycle implements SmartLifecycle{

    private final RpcApplicationServer server;

    private volatile boolean running;

    public RpcServerStartStopLifecycle(RpcApplicationServer server){
        this.server = server;
    }

    @Override
    public void start() {
        server.start();
        this.running = true;
    }

    @Override
    public void stop() {
        this.running = false;
        server.stop();
    }

    @Override
    public boolean isRunning() {
        return this.running;
    }

    @Override
    public int getPhase() {
        return Integer.MAX_VALUE - 1;
    }

}
